package cn.jbolt.websocket.auth.api;

import cn.jbolt.core.api.JBoltApiBaseController;
import cn.jbolt.core.api.OpenAPI;
import cn.jbolt.core.api.httpmethod.JBoltHttpGet;
import cn.jbolt.core.crossorigin.CrossOrigin;
import cn.jbolt.core.kit.JBoltSnowflakeKit;
import cn.jbolt.websocket.JBoltWebSocketUtil;
import com.jfinal.core.Path;
import com.jfinal.core.paragetter.Para;

@CrossOrigin
@Path("/api/websocket/guest")
public class JBoltGuestWebSocketApiController extends JBoltApiBaseController {

    /**
     * 生成临时websocket token
     */
    @JBoltHttpGet
    @OpenAPI
    public void genToken(){
        String token = "guest_ws_token_"+ JBoltSnowflakeKit.me.nextIdStr();
        renderJBoltApiSuccessWithData(JBoltWebSocketUtil.getGuestWebsocketToken(token));
    }

    /**
     * check 临时token
     */
    @JBoltHttpGet
    @OpenAPI
    public void checkToken(@Para("token")String token){
        renderJBoltApiSuccessWithData(JBoltWebSocketUtil.checkGuestWebsocketToken(token));
    }
}
